package com.dhn.controller;

import com.dhn.entity.Department;
import com.dhn.service.DepartmentService;
import com.dhn.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @RequestMapping("getDepartments")
    @ResponseBody
    public Object getDepartments(Department department){
        int total = departmentService.getTotal(department);
        department.setPage((department.getPage()-1)*department.getLimit());
        List<Department> list = departmentService.getDepartments(department);
        return Result.toClient("0","",total,list);
    }

    @RequestMapping("delDepartment")
    @ResponseBody
    public Object delDepartment(int id){
        int n = departmentService.delDepartment(id);
        if(n>0){
            return Result.toClient("0","删除成功！");
        }else{
            return Result.toClient("1","删除失败！");
        }
    }
}
